/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.nbg.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.nbg.entity.NbgBeixuan;
import com.zcm.modules.nbg.service.NbgBeixuanService;

/**
 * beixuanController
 * @author www
 * @version 2018-10-02
 */
@Controller
@RequestMapping(value = "${adminPath}/nbg/nbgBeixuan")
public class NbgBeixuanController extends BaseController {

	@Autowired
	private NbgBeixuanService nbgBeixuanService;
	
	@ModelAttribute
	public NbgBeixuan get(@RequestParam(required=false) String id) {
		NbgBeixuan entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = nbgBeixuanService.get(id);
		}
		if (entity == null){
			entity = new NbgBeixuan();
		}
		return entity;
	}
	
	@RequiresPermissions("nbg:nbgBeixuan:view")
	@RequestMapping(value = {"list", ""})
	public String list(NbgBeixuan nbgBeixuan, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<NbgBeixuan> page = nbgBeixuanService.findPage(new Page<NbgBeixuan>(request, response), nbgBeixuan); 
		model.addAttribute("page", page);
		return "modules/nbg/nbgBeixuanList";
	}

	@RequiresPermissions("nbg:nbgBeixuan:view")
	@RequestMapping(value = "form")
	public String form(NbgBeixuan nbgBeixuan, Model model) {
		model.addAttribute("nbgBeixuan", nbgBeixuan);
		return "modules/nbg/nbgBeixuanForm";
	}

	@RequiresPermissions("nbg:nbgBeixuan:edit")
	@RequestMapping(value = "save")
	public String save(NbgBeixuan nbgBeixuan, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, nbgBeixuan)){
			return form(nbgBeixuan, model);
		}
		nbgBeixuanService.save(nbgBeixuan);
		addMessage(redirectAttributes, "保存beixuan成功");
		return "redirect:"+Global.getAdminPath()+"/nbg/nbgBeixuan/?repage";
	}
	
	@RequiresPermissions("nbg:nbgBeixuan:edit")
	@RequestMapping(value = "delete")
	public String delete(NbgBeixuan nbgBeixuan, RedirectAttributes redirectAttributes) {
		nbgBeixuanService.delete(nbgBeixuan);
		addMessage(redirectAttributes, "删除beixuan成功");
		return "redirect:"+Global.getAdminPath()+"/nbg/nbgBeixuan/?repage";
	}

}